import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:pornhub_app/assets/assets.dart';
import 'package:pornhub_app/components/image_view.dart';
import 'package:pornhub_app/components/app_bar/app_bar_view.dart';
import 'package:pornhub_app/components/base_refresh/base_refresh_widget.dart';
import 'package:pornhub_app/components/no_more/no_data_scroll_view.dart';
import 'package:pornhub_app/components/text_view.dart';
import 'package:pornhub_app/model/mine/message_conter_model.dart';
import 'package:pornhub_app/utils/color.dart';

import '../controllers/new_followers_page_controller.dart';

class NewFollowersPage extends StatefulWidget {
  const NewFollowersPage({super.key});

  @override
  _NewFollowersPageState createState() => _NewFollowersPageState();
}

class _NewFollowersPageState extends State<NewFollowersPage> {
  final controller = Get.find<NewFollowersPageController>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBarView(
        titleText: '新关注我的',
        isShowBottomLine: true,
      ),
      body: _bodyViews(),
    );
  }

  Widget _bodyViews() {
    return BaseRefreshWidget(
      controller,
      child: Padding(
        padding: EdgeInsets.symmetric(horizontal: 14.w),
        child: Obx(() => controller.newFanlist.value.length > 0
            ? ListView.builder(
                itemCount: controller.newFanlist.value.length,
                itemBuilder: (context, index) =>
                    _itemView(controller.newFanlist.value[index]),
              )
            : NoDataScrollView()),
      ),
    );
  }

  Widget _itemView(MessageConterModel model) {
    final isAttention = model.attentionHe ?? false;
    return Container(
      height: 44.h,
      width: double.infinity,
      margin: EdgeInsets.only(bottom: 15.h),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        mainAxisSize: MainAxisSize.max,
        children: [
          ImageView(
            src: model.producerLogo ?? "",
            width: 44.w,
            height: 44.w,
            defaultPlace: Assets.avatarplaceholer,
            fit: BoxFit.cover,
            borderRadius: BorderRadius.circular(20.w),
          ),
          Expanded(
            child: Container(
              margin: EdgeInsets.symmetric(horizontal: 10.w),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  TextView(
                    text: "${model.producerName}",
                    fontSize: 14.sp,
                    color: COLOR.color_333333,
                    fontWeight: FontWeight.w600,
                  ),
                  TextView(
                    text: model.msgActionDesc ?? "",
                    fontSize: 10.sp,
                    color: COLOR.color_999999,
                  ),
                ],
              ),
            ),
          ),
          GestureDetector(
            onTap: () async {
              SmartDialog.showLoading(msg: '操作中...');
              if (isAttention) {
                await controller.follwersCancel(
                    toUserId: model.producerUserId ?? 0);
              } else {
                await controller.follwers(toUserId: model.producerUserId ?? 0);
              }
              model.attentionHe = !isAttention;
              SmartDialog.dismiss();
              setState(() {});
            },
            child: Container(
              width: 70.w,
              height: 25.h,
              alignment: Alignment.center,
              decoration: BoxDecoration(
                color: isAttention ? Colors.white : COLOR.color_FF4340,
                border: Border.all(color: COLOR.color_FFB5B5, width: 1),
                borderRadius: BorderRadius.circular(19.w),
              ),
              child: TextView(
                text: isAttention ? "相互关注" : "回关",
                fontSize: 12.sp,
                color: isAttention ? COLOR.color_FF4340 : COLOR.white,
              ),
            ),
          ),
        ],
      ),
    );
  }
}
